<?php require_once('Connections/local.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE events SET seats=%s WHERE eid=%s",
                       GetSQLValueString($_POST['hiddenField'], "int"),
                       GetSQLValueString($_POST['eid'], "int"));

  mysql_select_db($database_local, $local);
  $Result1 = mysql_query($updateSQL, $local) or die(mysql_error());

  $updateGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_Recordset1 = "-1";
if (isset($_GET['eid'])) {
  $colname_Recordset1 = $_GET['eid'];
}
mysql_select_db($database_local, $local);
$query_Recordset1 = sprintf("SELECT * FROM events WHERE eid = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $local) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.asd {
}
.button01 {
	height: 30px;
	width: 70px;
	background-color: #FFF;
	border: 1px solid #333;
	font-family: "微軟正黑體", "細明體";
	font-size: 14px;
	font-weight: bold;
}
a {
	font-family: "微軟正黑體", "細明體";
	font-size: 14px;
	color: #F03;
	font-weight: bold;
}
a:hover {
	color: #333;
	text-decoration: none;
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
</style>
</head>

<body>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td>訂票系統</td>
  </tr>
</table>
<p>&nbsp;</p>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr class="text">
    <td><a href="index.php">上一頁</a></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr class="text">
    <td width="139">活動時間</td>
    <td width="642">活動名稱</td>
    <td width="219">活動地點</td>
  </tr>
  <tr>
    <td class="date"><?php echo $row_Recordset1['e_time']; ?></td>
    <td class="date"><?php echo $row_Recordset1['e_name']; ?></td>
    <td class="date"><?php echo $row_Recordset1['e_location']; ?></td>
  </tr>
  <tr>
    <td class="text">活動介紹</td>
    <td colspan="2" rowspan="2" class="text"><?php echo $row_Recordset1['e_detail']; ?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" align="center"><form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
        <input name="eid" type="hidden" id="eid" value="<?php echo $row_Recordset1['eid']; ?>" />
        <input name="hiddenField" type="hidden" id="hiddenField" value="<?php  $a = (int)$row_Recordset1['seats']-1; echo $a;  ?>" />
        <input type="hidden" name="MM_update" value="form1" />
        <input  type="submit" name="button" id="button" value="購票" class="button01"  <?php if((int)$row_Recordset1['seats']==0){echo 'disabled="disabled"';}; ?>/>
    </form></td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
